<template>
  <div style="width: 80%;">
      <div style="margin-bottom: 30px">编辑图书</div>
    <el-form :inline="true"   :model="form" :rules="rules" ref="ruleForm"  style="width: 70%" label-width="200px">

      <el-form-item label="名称" prop="name">
        <el-input v-model="form.name" placeholder="请输入名称"></el-input>
      </el-form-item>

      <el-form-item label="描述" prop="description">
        <el-input style="width: 400px" type="textarea" v-model="form.description" placeholder="请输入描述"></el-input>
      </el-form-item>

      <el-form-item label="出版日期" prop="publishDate">
        <el-date-picker
            v-model="form.publishDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择出版出版日期">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="标准码" prop="bookNo">
        <el-input v-model="form.bookNo" placeholder="请输入标准码"></el-input>
      </el-form-item>


      <el-form-item label="借书积分" prop="score">
        <el-input v-model="form.score" placeholder="请输入积分"></el-input>
        <el-input-number v-model="form.score"  :min="10" :max="30" label="所需积分"></el-input-number>
      </el-form-item>


    </el-form>

    <div style="text-align: center;margin-top: 30px ">
      <el-button type="primary"  @click="save" size="medium">提交</el-button>
<!--      <el-button type="danger">返回列表</el-button>-->
    </div>

  </div>
</template>

<script>
import request from "@/utils/request";
export default {
  name: 'EditCategory',
  data(){
    return{
      form:{
        score:10
      },
      rules: {
        name: [
          {required: true, message: '请输入分类名称', trigger: 'blur'}
        ],
        bookNo: [
          {required: true, message: '请输入图书标准码', trigger: 'blur'}
        ],
        score: [
          {required: true, message: '请输入借书积分', trigger: 'blur'}
        ],
      }
    }

  },
  created() {
   const  id = this.$route.query.id
    request.get("/book/"+id).then(res => {
      this.form = res.data
    })
  },
  methods:{
    save(){
      request.put('/book/update',this.form).then(res =>{
        if (res.code === '200' ){
          this.$notify.success('更新成功')
          this.$router.push("/adminList")
        }else {
          this.$notify.error(res.msg)
        }
      })
    }
  }
}
</script>